package com.example.demo02.controller.Swagger;

import com.example.demo02.Swaggerdemo.User;
import com.example.demo02.Swaggerdemo.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "User接口")
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @Operation(summary  = "获取所有用户对象")
    @RequestMapping(value = "/findAllUsers", method = {RequestMethod.POST, RequestMethod.GET})
    public List<User> findAllUsers() {
        //查出所有用户数据
        return userService.findAllUsers();
    }

    @Operation(summary  = "根据姓名查找用户对象")
    @RequestMapping(value = "/findByName", method = {RequestMethod.POST, RequestMethod.GET})
    @Parameters({@Parameter(name = "username", description  = "用户名"),
                       @Parameter(name = "password", description  = "密码")})
    public User findByName(@Parameter(description  = "姓名", example = "张三", required = true) String username) {
        return userService.findUserByName(username);
    }
}
